{%- set interface_type=input_params.get('interface_type', 'physical')         %}

{%- set interface_stats_list = []                                             %}
{%- for physical_interface in command_resp.get('physical_intf_list')          %}
{%-     if interface_type == "physical"                                       %}
{%-         set interface_stat = {}                                           %}
{%-         set x = interface_stat.update({
                        "name":physical_interface.name,
                        "op_status":physical_interface.get('oper-status', ""),
                        "admin_status": physical_interface.get('admin-status', ""),
                        "input_rate": physical_interface.get('traffic-statistics', {}).get('input-bps', ""),
                        "output_rate": physical_interface.get('traffic-statistics', {}).get('output-bps', "")
                                           })                                 %}
{%-         set y = interface_stats_list.append(interface_stat)               %}
{%-     elif interface_type == "logical"                                      %}
{%-         if 'logical-interface' in physical_interface                      %}
{%-             if physical_interface.get('logical-interface') is mapping     %}
{%-                 set log_units = [physical_interface['logical-interface']] %}
{%-             else                                                          %}
{%-                 set log_units = physical_interface['logical-interface']   %}
{%-             endif                                                         %}
{%-             for log_interface in log_units                                %}
{%-                 set interface_stat = {}                                   %}
{%-                 set x = interface_stat.update({
                                "name":log_interface.name,
                                "op_status":log_interface.get('oper-status', ""),
                                "admin_status": log_interface.get('admin-status', ""),
                                "input_rate": log_interface.get('traffic-statistics', {}).get('input-bps', ""),
                                "output_rate": log_interface.get('traffic-statistics', {}).get('output-bps', "")
                                                   })                         %}
{%-                 set y = interface_stats_list.append(interface_stat)       %}
{%-             endfor                                                        %}
{%-         endif                                                             %}
{%-     endif                                                                 %}
{%- endfor                                                                    %}

{%- for logical_interface in command_resp.get('logical_intf_list')            %}
{%-     if interface_type == "logical"                                        %}
{%-         set interface_stat = {}                                           %}
{%-         set x = interface_stat.update({
                        "name":logical_interface.name,
                        "op_status":logical_interface.get('oper-status', ""),
                        "admin_status": logical_interface.get('admin-status', ""),
                        "input_rate": logical_interface.get('traffic-statistics', {}).get('input-bps', ""),
                        "output_rate": logical_interface.get('traffic-statistics', {}).get('output-bps', "")
                                           })                                 %}
{%-         set y = interface_stats_list.append(interface_stat)               %}
{%-     endif                                                                 %}
{%- endfor                                                                    %}


{"interface_stats": {{interface_stats_list | to_json}} }
